package adke.managers;

import adke.Util;
import adke.models.powerups.Powerup;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;

// kan plaatjes van powerups laden en teruggeven op de gewenste grootte

public class ImageManager
{
    public ImageManager()
    {
    }
    
    public static boolean imageAvailable(String powerupName)
    {
        String runPath = Util.getRunPath();
        return new File(makePath(powerupName)).exists();
    }
    
    public static boolean imageAvailable(Powerup p)
    {
        return imageAvailable(p.toString());
    }
    
    public static String makePath(String powerup)
    {
        return "img" + File.separator + powerup + ".png";
    }
    
    public static Image getImage(String powerup)
    {
        return Toolkit.getDefaultToolkit().createImage(makePath(powerup));
    }
    
    public static Image getImage(Powerup p)
    {
        return getImage(p.toString());
    }
    
    public static Image getEmptyImage()
    {
        int dimension = Powerup.IMG_DIMENSION;
        
        BufferedImage bimage = new BufferedImage(dimension, dimension, BufferedImage.TYPE_INT_ARGB);
        Graphics g = bimage.getGraphics();
        g.setColor(Color.RED);
        
        // kruis
        g.drawLine(0, 0, bimage.getWidth(), bimage.getHeight());
        g.drawLine(bimage.getWidth(), 0, 0, bimage.getHeight());
        
        // vierkant
        g.drawRect(1, 1, dimension-2, dimension-2);
        
        // schijnbaar kan de garbage collector dit niet
        g.dispose();
        
        return bimage;
    }
}
